﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;

public partial class Safty_Modify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) { Store1Databind(); }
    }
    protected void Store1Databind()
    {
        Query q = new Query(VwStaffSaftyStep1.Schema);
        q.SetSelectList("id,en_username,en_department,safty_master_status,dept_master_status,boss_status,intime");
        q.AddWhere("enteringuserid", Cookies.getCookies("cuid"));
        q.AddWhere("safty_master_status",2);
        Store1.DataSource = q.ExecuteDataSet();
        Store1.DataBind();
    }
    protected void DeleteRow(object s, AjaxEventArgs e)
    {
        string id = e.ExtraParams["id"].ToString();

        CxStaffSafty.Delete("id", id);
        Err.Warning("删除成功！", MessageBox.Icon.NONE);
        Store1.DataBind();
        Clear();
    }
        
    protected void Store1_OnRefreshData(object s, StoreRefreshDataEventArgs e)
    {
        Store1Databind();
    }
    protected void RowSelect(object s, AjaxEventArgs e)
    {
        string id = e.ExtraParams["id"].ToString();
        Query q = new Query(VwStaffSaftyStep1.Schema);
        q.AddWhere("id", id);
        IDataReader dr = q.ExecuteReader();
        if (dr.Read())
        {
            Tfusername.Text = dr["en_username"].ToString();
            TfSafty_MasterId.SetInitValue(dr["safty_masterid"].ToString());
            tfhiddenid.Value = id;
            tfhiddenguid.Value = dr["guid"].ToString();
            TfDeptName.Text = dr["en_department"].ToString();
            TfAccident_time.Value = dr["accident_time"].ToString();
            TfAccident_reason.Text = dr["accident_reason"].ToString();
            TfAccident_duty.SetInitValue(dr["accident_duty"].ToString());
            tfsafty_master_remark.Text = dr["safty_master_remark"].ToString();

            switch (dr["safty_master_status"].ToString())
            {
                case "0":
                    tfsafty_master_status.Text = "未审核";
                    break;
                case "1":
                    tfsafty_master_status.Text = "同意";
                    break;
                case "2":
                    tfsafty_master_status.Text = "退回";
                    break;
                    
            }
            
        }
    }
    protected void SubReportAdd(object s, AjaxEventArgs e)
    {
        if (tfhiddenid.Value == "") { Err.Warning("请选择一份档案！", MessageBox.Icon.WARNING); return; }
        CxStaffSafty cx = new CxStaffSafty("id",tfhiddenid.Value.ToString());
        if (TfAccident_time.Value.ToString() != "0001/1/1 0:00:00")
        {
            cx.AccidentTime = DateTime.Parse(TfAccident_time.Value.ToString());
        }
        cx.AccidentDuty = TfAccident_duty.SelectedItem.Value.ToString();
        cx.AccidentReason = TfAccident_reason.Text;
        cx.SaftyMasterStatus = 0;
        cx.Save();
        CXFileUpload.Del(tfhiddenguid.Value.ToString());
        CXFileUpload.Sv(tffileupload, new Guid(tfhiddenguid.Value.ToString()));
        Err.Warning("修改提交成功！", MessageBox.Icon.NONE);
        Clear();
        
    }
    protected void Clear()
    {
        Tfusername.Text = "";
        TfSafty_MasterId.Reset();
        tfhiddenid.Value = "";
        tfhiddenguid.Value = "";
        TfDeptName.Text ="";
        TfAccident_time.Value = "";
        TfAccident_reason.Text = "";
        TfAccident_duty.Reset();
        tfsafty_master_remark.Text ="";
        tfsafty_master_status.Text = "";
    }
}
